﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Xml;
using bmapi.Models.DataEntity;

namespace bmapi.Controllers
{
    [RoutePrefix("cadName"),JwtAuthActionFilter]
    public class CADNameController : CADController
    {
        /// <summary>
        /// 查询样式名是否存在
        /// </summary>
        /// <param name="modelName">样式名</param>
        /// <returns></returns>
        [HttpGet,Route("CheckModelName/{modelName}")]       
        public string CheckModelName(string modelName)
        {
            WriteLog("CheckModelName", "modelName:"+ modelName, true);
            try
            {
                string sql = "select name from Model_tb where name=@name and state=2";
                SQLCommand sc = new SQLCommand(sql, "@name", modelName);
                if (sc.ExecuteScalar() == null)
                    return "false";
                else
                    return "true";
            }
            catch (Exception e)
            {
                WriteLog("CheckModelname", e.Message);
                return "true";
            }
        }
        /// <summary>
        /// 查询款式是否存在
        /// </summary> 
        /// <param name="styleName">款式名</param>
        /// <returns></returns>
        [HttpGet,Route("CheckStyleName/{styleName}")]
        public string CheckStyleName( string styleName)
        {
            if (CheckStylename(styleName))
                return "true";
            else
                return "false";
        }
        /// <summary>
        /// 查询订单号是否存在
        /// </summary>
        /// <param name="orderName">订单号</param>
        /// <returns></returns>
        [HttpGet,Route("CheckOrderName/{orderName}")]
        public string CheckOrderName(string orderName)
        {
            if (CheckOrdername(orderName))
                return "true";
            else
                return "false";
        }
        /// <summary>
        /// 查询某个流程名（样式名/生产单号）
        /// </summary>
        /// <param name="pcid">PC_tb表中的流程ID</param>
        /// <param name="process">工序编码</param>
        /// <returns></returns>
        [HttpGet,Route("GetTaskName/{id}/{process}")]
        public string GetTaskName(int pcid, int process)
        {
            WriteDebug("GetTaskName/{id}/{process}", pcid.ToString());
            return GetPCName(pcid);           
        }

        [HttpGet,Route("GetModelInfo/{modelName}")]
        public string GetModelInfo(string modelName)
        {
            return GetModelinfo(modelName);           
        }
    }
}
